package com.itheima;

public class Test3 {
    public static void main(String[] args) {
        
    }

    public ListNode removeNthFromEnd(ListNode head, int n) {
        //虚拟头结点
        ListNode dummy=new ListNode(0,head);
        //头指针
        ListNode first=head;
        //尾指针
        ListNode second =dummy;
        //让头指针指到他应该到的位置
        for(int i =0;i<n;i++){
            first=first.next;
        }
        //头指针带动尾指针
        while(first!=null){
            first=first.next;
            second=second.next;
        }
        //删除要删除的节点
        second.next=second.next.next;
        //返回真正的头结点
        return dummy.next;
    }
}
